package cn.itcast.mq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class CommonConfig  implements ApplicationContextAware {
    @Override
    /**
     * 发送者确认
     * 这里我是理解为发送到队列的确认
     */
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        RabbitTemplate rabbitTemplate = applicationContext.getBean(RabbitTemplate.class);
        rabbitTemplate.setReturnCallback((message, replyCode, replyText, exchanged, routingKey) -> {
            log.info("message(消息！):{} replyCode(应答！){}:replyText(原因)：{}exchanged(交换机名子):{}routingKey(路由键):{}",
                    message,replyCode,replyText,exchanged,routingKey);
        });
    }
}
